using UnityEngine;
using UnityEngine.Events;

public class GlassMoveTo : MonoBehaviour
{
	public float angle;

	public float angleAnimationTime;

	public float animationTime;

	public UnityEvent onAnimationEnd = new UnityEvent();

	private Vector3 targetPosition;

	private Vector3 initialPosition;

	private Vector3 initialAngle;

	private float playTime;

	private bool playing;

	public void Play(Vector3 position)
	{
		initialPosition = base.transform.position;
		initialAngle = base.transform.localEulerAngles;
		targetPosition = position;
		playing = true;
		playTime = 0f;
	}

	private void Update()
	{
		if (playing)
		{
			playTime += Time.deltaTime;
			base.transform.localEulerAngles = Vector3.Lerp(initialAngle, Vector3.forward * angle, playTime / angleAnimationTime);
			base.transform.position = Vector3.Lerp(initialPosition, targetPosition, playTime / animationTime);
			if (base.transform.position == targetPosition)
			{
				onAnimationEnd.Invoke();
				playing = false;
			}
		}
	}
}
